package com.lx.listenerDemo;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * 监听器的定义及应用
 * 1.Listener:控制Job执行的一种方式
 * 2.可以通过接口或者注解实现监听器
 * 3.在spring-batch中提供各个级别的监听器接口，从job级别到item级别都有
 * （1）JobExecutionListener(before…,after…);
 * （2）StepExecutionListener(before…,after…);
 * （3）ChunkListener(before…,after…);
 * （4）ItemReaderListener;ItemWriterListener;ItemProcessListener(before…,after…,error…);
 * 实现接口构建监听器
 * @author lixing
 * @date 2021/7/12 15:31
 */
public class MyJobListener implements JobExecutionListener {

    @Override
    public void beforeJob(JobExecution jobExecution) {
        System.out.println(jobExecution.getJobInstance().getJobName()+"before running......");
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        System.out.println(jobExecution.getJobInstance().getJobName()+"before running......");
    }

}
